library(tidyverse)
library(readxl)
path = "Excel/700-799/748/748 Diamond.xlsx"
test = read_excel(path, range = "B2:R18", col_names = FALSE) %>% as.matrix()
n = 9
s = 2*n - 1
m = outer(1:s,
1:s,
function(i, j) ifelse((d = abs(i - n) + abs(j - n)) < n, n - d, NA_integer_))
all(m == test, na.rm = TRUE)
# > [1] TRUEExcel BI - Excel Challenge 748
excel-challenges
excel-formulas
🔰 Produce the given diamond of numbers as shown

Challenge Description
🔰 Produce the given diamond of numbers as shown
Solutions
- Logic: Read the workbook ranges needed for the challenge; Apply the business rule conditions explicitly.
- Strengths: The code maps the workbook rule into a compact, reproducible pipeline.
- Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
- Gem: The elegant part is how little code is needed once the correct intermediate representation is chosen.
import numpy as np
import pandas as pd
path = "700-799/748/748 Diamond.xlsx"
test = pd.read_excel(path, header=None, skiprows=1, nrows=17, usecols="B:R").to_numpy()
n = 9
y, x = np.ogrid[:2*n-1, :2*n-1]
m = np.where(np.abs(y-n+1) + np.abs(x-n+1) < n, n - (np.abs(y-n+1) + np.abs(x-n+1)), np.nan)
print(np.allclose(test, m, equal_nan=True))The Python version mirrors the same workbook logic with a concise, direct implementation.
Difficulty Level
Easy / Medium
The business rule is clear, though the workbook still needs a few transformation steps to reach the expected output.